/*
  学习目标：底层原理-setState更新
    1. setState更新是异步的
    2. 连续调用setState更新同一个变量, 会产生合并效果
  合并:
    最后一个setState会覆盖前面所有的setState
  设计目的:
    减少操作dom的次数, 减少性能浪费
*/

import React, { Component } from 'react';

export default class App extends Component {
  state = {
    count: 0,
  };

  handleAdd = () => {
    this.setState({ count: this.state.count + 1 });
    this.setState({ count: this.state.count + 2 });
    this.setState({ count: this.state.count + 3 });

    console.log('this.state.count  ----->  ', this.state.count);
  };

  render() {
    console.log('render执行了  ----->  ');
    const { count } = this.state;

    return (
      <div>
        App
        <h1>{count}</h1>
        <button onClick={this.handleAdd}>点我</button>
      </div>
    );
  }
}
